package com.loveshare.backend.rest;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.loveshare.backend.entity.AdminUser;
import com.loveshare.backend.service.AdminUserService;

@RestController
@RequestMapping(value="backend")
public class AdminUserRest {
	
	@Autowired
	private AdminUserService adminUserService;
	
	/**
	 * 判断用户是否登录
	 * @param userName
	 * @param password
	 * @return
	 */
	@RequestMapping(value="/checkLogin",method=RequestMethod.POST)
	public boolean checkLogin(@RequestParam(defaultValue="") String userName,@RequestParam(defaultValue="") String password
			,HttpServletRequest request){
		AdminUser adminUser=new AdminUser();
		adminUser.setPassword(password);
		adminUser.setUserName(userName);
		int i=adminUserService.checkAdminUser(adminUser);
		if(i!=0){
			request.getSession().setAttribute("adminId", userName);
			return true;
		}
		return false;
	}
}
